package org.magicbox.qjunTPO.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfigration implements WebMvcConfigurer {

    //我还是使用NGINX来实现吧,不劳烦后端服务器做资源的映射了
    //配置文件获取虚拟路径的映射
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
////        WebMvcConfigurer.super.addResourceHandlers(registry);
//        //开发环境的路径的映射
//        registry.addResourceHandler("/getImg/**").addResourceLocations("file:E://http//qjunTPO//img//");
//
//        //生产环境的路径的映射
////        registry.addResourceHandler("/getImg/**").addResourceLocations("file:/www/data/qjunTpo/img/");
////        registry.addResourceHandler("/虚拟路径/**").addResourceLocations("file:被映射的路径//");
//    }

    /**
     * 跨域问题解决
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET","POST")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}